var scoreSql = {
	
}
/*
// 用户表
CREATE TABLE IF NOT EXISTS userTb (
  id INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(45) DEFAULT NULL,
  uid DATE DEFAULT NULL,
  date_time DATE DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
// 修改字段类型
alter table userTb modify column uid text;
alter table userTb modify column name text;
insert into userTb (name,uid,date_time) values ('小明','123456',NOW());
insert into userTb (name,uid,date_time) values ('小红','123457',NOW());
insert into userTb (name,uid,date_time) values ('小白','123458',NOW());
insert into userTb (name,uid,date_time) values ('小张','123458',NOW());
insert into userTb (name,uid,date_time) values ('小李','123459',NOW());

insert into userTb (name,uid,date_time) values ('小王','223456',NOW());
insert into userTb (name,uid,date_time) values ('小刘','223457',NOW());
insert into userTb (name,uid,date_time) values ('小朱','223458',NOW());
insert into userTb (name,uid,date_time) values ('小马','223458',NOW());
insert into userTb (name,uid,date_time) values ('小二','223459',NOW());

insert into userTb (name,uid,date_time) values ('小一','323456',NOW());
insert into userTb (name,uid,date_time) values ('小三','323457',NOW());
insert into userTb (name,uid,date_time) values ('小四','323458',NOW());
insert into userTb (name,uid,date_time) values ('小五','323458',NOW());
insert into userTb (name,uid,date_time) values ('小六','323459',NOW());


// 积分表
CREATE TABLE IF NOT EXISTS scoreTb (
  id INT(11) NOT NULL AUTO_INCREMENT,
  uid TEXT DEFAULT NULL,
  score TEXT DEFAULT NULL,
  date_time DATE DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
select * from scoreTb;
select * from userTb;
insert into scoreTb (uid,score,date_time) values ('123456','1',NOW());
insert into scoreTb (uid,score,date_time) values ('123457','1',NOW());
insert into scoreTb (uid,score,date_time) values ('123458','2',NOW());
insert into scoreTb (uid,score,date_time) values ('223458','1',NOW());
insert into scoreTb (uid,score,date_time) values ('223459','1',NOW());
insert into scoreTb (uid,score,date_time) values ('323456','1',NOW());
insert into scoreTb (uid,score,date_time) values ('323457','1',NOW());

// 修改字段名
alter table scoreTb change name score text;
// SUM
select uid, SUM(score) as total from scoreTb group by uid order by total desc limit 5;
select uid, SUM(score) as total from scoreTb order by total desc;
select SUM(score) as total from scoreTb ORDER BY uid;
select *from scoreTb where uid=323457;

select * from userTb where uid in (select uid, SUM(score) as total from scoreTb group by uid order by total desc limit 5);
select * from userTb U where not exists (select T.uid from (select uid, SUM(score) as total from scoreTb group by uid order by total desc) T on T.uid=U.uid) limit 5;
select * from userTb where uid in (select t.uid from (select uid, from scoreTb group by uid order by SUM(score) as total desc limit 5) as t);
select * from userTb t left join (select sum(score) as my_score, max(uid) from scoreTb group by uid) tab on tab.uid = t.uid limit 1,5;
select *
  from userTb t
  left join (select sum(score) as my_score, max(uid) as uid
               from scoreTb
              group by uid) tab
    on tab.uid = t.uid order by tab.my_score desc limit 5;
    
  select *
  from userTb t
  left join (select sum(score) as my_score,uid
               from scoreTb
              group by uid) tab
    on tab.uid = t.uid order by tab.my_score desc limit 5;
    
  select *
  from userTb t
  left join (select sum(score) as my_score,uid
               from scoreTb
              group by uid order by my_score desc) tab
    on tab.uid = t.uid limit 5;
select * from userTb left join (select uid, SUM(score) as total from scoreTb group by uid order by total desc limit 5) tab on t.uid=tab.uid;
    
* */









